// 7_1.c Variable Scope
#include <stdio.h>
int firstnum;  /*create a global variable named firstnum*/
void valfun();   /*function prototype*/

int main()
{
    int secnum;  /*create a local variable named secnum*/
    firstnum=10; /*store a value into the global variable*/
    secnum=20;   /*store a value into the local variable*/

    printf("\nFrom main(): firstnum=%d",firstnum);
    printf("\nFrom main(): secnum=%d\n",secnum);

    valfun(); /*call the function valfun*/
    
    printf("\nFrom main() again: firstnum=%d",firstnum);
    printf("\nFrom main() again: secnum=%d\n",secnum);
   
    return 0;
}

void valfun()   /*no value are passed to this function*/
{
    int secnum;  /*create a second local variable named secnum*/
    secnum =30;   /*this only affects this local variable's value*/

    printf("\nFrom valfun(): firstnum=%d",firstnum);
    printf("\nFrom valfun(): secnum=%d\n",secnum);
    firstnum=40;  /*this changes firstnum for both functions*/
}
    
